//
//  KSWebItem.swift
//  ANOA
//
//  Created by 邱仙凯 on 2022/4/25.
//  Copyright © 2025 aowang. All rights reserved.
//  网页

import UIKit
import WebKit

class KSWebItem: KSFormHItem {
    lazy var webV:WKWebView = {
       let v = WKWebView()
        return v
   }()
    convenience init(appearance: KSFormBaseAppear? = KSFormBaseAppear()) {
        self.init(title: "", appearance: appearance,type:.web)
        
        self.addSubview(webV)
        webV.navigationDelegate = self
        webV.snp.makeConstraints { make in
            make.right.equalTo(self)
            make.left.equalTo(self)
            make.top.equalTo(self).offset(3)
            make.bottom.equalTo(self).offset(-3)
        }
     }
  
    // 设置web内容
     func setWebHtml(_ str:String?) {
         self.webV.loadHTMLString(str.unwrap, baseURL: nil)
      }
}
extension KSWebItem:WKNavigationDelegate {
    
     func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        
        /// wkWebView调用js方法
        let js = "document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '200%'"
        webView.evaluateJavaScript(js) { (response, error) in
            print("response:", response ?? "No Response", "\n", "error:", error ?? "No Error")
 
        }
   
    }
    
}
